<script setup lang="ts">
import {useRouter} from 'vue-router'
import {userStore} from "@/store/user"
import {onMounted, ref} from "vue";

const props = defineProps({
  messageList: {
    type: Array<any>,
    default: () => []
  },
  type: {
    type: String
  }
})
const router = useRouter()
let userInfo = ref<any>({})
const gotoDetail = (item: any) => {
  if (props.type === 'system') {
    router.push('/message/systemList')
  }
  // if(props.type === 'talk' && item.things_type ===0){
  //     router.push('/message/talk/'+item.things_id +'/'+item.receive_id)
  // }
  if (props.type === 'talk') {
      if(userInfo.value.userId == item.recipientId){
        router.push('/message/talk/' + item.senderId)
      }else{
        router.push('/message/talk/' + item.recipientId)
      }
  }
  // if(props.type === 'talk' && item.things_type ===1){
  //     router.push('/message/talent/'+item.things_id +'/'+item.send_id)
  // }
  // if(props.type === 'talent' && item.things_type ===0){
  //     router.push('/message/talk/'+item.things_id +'/'+item.send_id)
  // }
  // if(props.type === 'talent' && item.things_type ===1){
  //     router.push('/message/talent/'+item.things_id +'/'+item.receive_id)
  // }
}

onMounted(()=>{
  userStore().getUserInfo().then(res => {
    userInfo.value = res
  })
})
</script>
<template>
  <dl v-for="(item,index) in messageList" :key="index" @click="gotoDetail(item)">
    <dd>
      <img v-if="item.receive_is_read" :src="item.receive_is_read">
      <img v-else src="@/assets/img/icon/icon-message.png">
      <!--            <span v-if="item.is_show"></span>-->
    </dd>
    <dt>
      <h3 v-if="userInfo.userId == item.recipientId">{{ item.senderName }}<span>{{ item.createTime }}</span></h3>
      <h3 v-else>{{ item.recipientName }}<span>{{ item.createTime }}</span></h3>
      <p>{{ item.msg }}</p>
    </dt>
  </dl>
</template>
<style scoped>
dl {
  font-size: 0.64rem;
  color: #666666;
  padding: 0.9rem 0;
  margin: 0 0.67rem;
  border-bottom: 1px solid #eeeeee;
  display: flex;
  align-items: center;
}

dl dd {
  position: relative;
  margin-right: 0.56rem;
}

dl dd img {
  width: 2.61rem;
  height: 2.61rem;
  border-radius: 50%;
}

dl dd span {
  position: absolute;
  top: 0;
  right: 0;
  width: 0.32rem;
  height: 0.32rem;
  background: #FF0000;
  border-radius: 50%;
}

dl dt {
  flex: 1;
}

dl dt h3 {
  font-size: 0.8rem;
  line-height: 0.8rem;
  font-weight: 500;
  color: #333333;
  margin-bottom: 0.43rem;
}

dl dt h3 span {
  float: right;
  color: #999999;
  font-size: 0.64rem;
  font-weight: 100;
}

dl dt p {
  font-size: 0.69rem;
  line-height: 0.69rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
</style>